home *** CD-ROM | disk | FTP | other *** search
/ Programming in Microsoft Windows with C# / Programacion en Microsoft Windows con C#.iso / Original Code / Lines Curves and Area Fills / Spiral / Spiral.cs next >
Encoding:
Text File  |  2001-01-15  |  1.1 KB  |  36 lines

  1. //-------------------------------------
  2. // Spiral.cs ⌐ 2001 by Charles Petzold
  3. //-------------------------------------
  4. using System;
  5. using System.Drawing;
  6. using System.Windows.Forms;
  7.  
  8. class Spiral: PrintableForm
  9. {
  10.      public new static void Main()
  11.      {
  12.           Application.Run(new Spiral());
  13.      }
  14.      public Spiral()
  15.      {
  16.           Text = "Spiral";
  17.      }
  18.      protected override void DoPage(Graphics grfx, Color clr, int cx, int cy)
  19.      {
  20.           const int iNumRevs   = 20;
  21.           int       iNumPoints = iNumRevs * 2 * (cx + cy);
  22.           PointF[]  aptf       = new PointF[iNumPoints];
  23.           float     fAngle, fScale;
  24.  
  25.           for (int i = 0; i < iNumPoints; i++)
  26.           {
  27.                fAngle = (float)(i * 2 * Math.PI /(iNumPoints / iNumRevs));
  28.                fScale = 1 - (float)i / iNumPoints;
  29.  
  30.                aptf[i].X = (float)(cx / 2 * (1 + fScale * Math.Cos(fAngle)));
  31.                aptf[i].Y = (float)(cy / 2 * (1 + fScale * Math.Sin(fAngle)));
  32.           }
  33.           grfx.DrawLines(new Pen(clr), aptf);
  34.      }
  35. }
  36.